package pl.edu.agh.logview.model.helper;

import java.sql.SQLException;

import pl.edu.agh.logview.database.DbHelper;
import pl.edu.agh.logview.model.Agent;
import pl.edu.agh.logview.model.VertexType;

public class AgentHelper {

	private DbHelper dbHelper;
	
	public AgentHelper(){
		dbHelper = new DbHelper();
	}
	
	public Agent buildAgent(String agentName){
		Agent agent = null;
		
		try {
			agent = dbHelper.getAgentDao().queryForId(agentName);
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		
		if(agent==null){
			agent = new Agent();
			agent.setName(agentName);
			agent.setVertexObject(VertexType.VERTEX_AGENT);
			
			try {
				dbHelper.getAgentDao().create(agent);
			} catch (SQLException e) {
				e.printStackTrace();
				return null;
			}
		}
		
		return agent;
	}
}
